﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IFClientDLL;
using FrmTryIF.Ctl.Calc;

namespace IFViewDetail.Ctl.Demo.PlayMarket
{
    public partial class CtlPlayMarket : UserControl
    {
        public CtlPlayMarket()
        {
            InitializeComponent();
        }
        private ITryIF _tryif;
        IPlay _p;
        public IPlay Player { get { return _p; } }
        public void InitTryIF(ITryIF tryIF)
        {
            _tryif = tryIF;
            _p = _tryif.DataServer as IPlay;
            _tryif.DataServer.OnReceiveDBData += new Action<IFServerDLL.DB.MyDBData>(Tryif_OnReceiveData);

            simpleButton1.Enabled = !_p.IsPlaying;
            simpleButton2.Enabled = _p.IsPlaying;
            trackBarControl1.EditValue = 1;
            simpleButton1.ToolTip = tryIF.DataInfo.合约 + " " + tryIF.DataInfo.日期.ToShortDateString();
        }

        void Tryif_OnReceiveData(IFServerDLL.DB.MyDBData obj)
        {
            lblTime.Text = obj.MarketTime.ToLongTimeString();
            progressBarControl1.Position = obj.GetTimePct();
        }


        private void trackBarControl1_EditValueChanged(object sender, EventArgs e)
        {
            _p.SetInterval(int.Parse(trackBarControl1.EditValue.ToString()));
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {

            _p.Play();
            simpleButton1.Enabled = !_p.IsPlaying;
            simpleButton2.Enabled = _p.IsPlaying;
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            _p.Pause();
            simpleButton1.Enabled = !_p.IsPlaying;
            simpleButton2.Enabled = _p.IsPlaying;
        }
        
        private void simpleButton3_Click(object sender, EventArgs e)
        {
            
        }

    }
}
